package com.rraj.common.domain;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.google.common.collect.Lists;
import com.rraj.common.encrypt.DESUtil;
import com.rraj.common.utils.DateUtils;
import com.rraj.common.utils.HttpUtil;

public class TradeResult {
	private int status;// 状态：0 失败 1：转入中 2:转入成功
	@JSONField(serialize = false)
	private BigDecimal totalAmount = BigDecimal.ZERO;// 交易金额
	@JSONField(serialize = false)
	private Date createTime;// 创建时间
	@JSONField(serialize = false)
	private String orderNo;// 订单号
	private String message;// 状态文本
	private String title;// 标题
	private List items;

	private List statusItem;

	/**红包金额**/
	@JSONField(serialize = false)
	private BigDecimal couponAmount = BigDecimal.ZERO;;

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public BigDecimal getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(BigDecimal totalAmount) {
		this.totalAmount = totalAmount;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getTitle() {
		if (title == null) {
			// return "转入成功";
		}
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List getItem() {
		return items == null ? getTradeList() : items;
	}

	private List getTradeList() {
		List list = Lists.newArrayList();
		JSONObject json = new JSONObject();
		json.put("key", "订单号");
		json.put("value", orderNo);
		list.add(json);
		JSONObject json1 = new JSONObject();
		json1.put("key", "转入金额(元)");
		String v = totalAmount.toString();
		if(couponAmount.compareTo(BigDecimal.ZERO) > 0){
			v=v+"(含"+couponAmount.setScale(0)+"元红包)";
		}
		json1.put("value", v);
		list.add(json1);
		JSONObject json2 = new JSONObject();
		json2.put("key", "创建时间");
		json2.put("value", DateUtils.getStringDate(getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
		list.add(json2);
		return list;
	}

	/**
	 * 添加显示项
	 * 
	 * @param key
	 * @param value
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public TradeResult putItem(String key, Object value) {
		if (items == null) {
			items = new ArrayList<>();
		}
		JSONObject json2 = new JSONObject();
		json2.put("key", key);
		json2.put("value", value);
		items.add(json2);
		return this;
	}


	public List getStatusItem() {
		if (statusItem == null) {
			statusItem = new ArrayList<>();
		}
		return statusItem;
	}

	public void setStatusItem(List statusItem) {
		this.statusItem = statusItem;
	}

	/**
	 * 添加状态项
	 * 
	 * @param key
	 * @param value
	 * @param isFinish
	 *            是否完成
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public TradeResult putStatusItem(String key, Object value, boolean isFinish) {
		JSONObject json2 = new JSONObject();
		json2.put("key", key);
		json2.put("value", value);
		json2.put("status", isFinish ? 1 : 0);
		getStatusItem().add(json2);
		return this;
	}


	public BigDecimal getCouponAmount() {
		return couponAmount;
	}

	public void setCouponAmount(BigDecimal couponAmount) {
		this.couponAmount = couponAmount;
	}
}
